import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/qian',
    component: () => import('@/views/qian/index'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '订单', icon: 'el-icon-shopping-cart-full' }
    }]
  },

  {
    path: '/game',
    component: Layout,
    children: [
      {
        name: 'game',
        path: '/game',
        component: () => import('@/views/game/game'),
        meta: { title: '游戏', icon: 'el-icon-star-off' }
      }
    ]
  },

  {
    path: '/partner',
    component: Layout,
    children: [
      {
        name: 'partner',
        path: '/partner',
        component: () => import('@/views/partner/partner'),
        meta: { title: '项目', icon: 'el-icon-sell' }
      }
    ]
  },

  {
    path: '/systems',
    component: Layout,
    children: [
      {
        name: 'systems',
        path: '/systems',
        component: () => import('@/views/systems/systems'),
        meta: { title: '系统', icon: 'el-icon-s-platform' }
      }
    ]
  },

  {
    path: '/playd',
    component: Layout,
    children: [
      {
        name: 'plays',
        path: '/plays',
        component: () => import('@/views/playd/playd'),
        meta: { title: '陪玩', icon: 'el-icon-s-grid' }
      }
    ]
  },

  {
    path: '/qian',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/qian/index'),
      meta: { title: '订单', icon: 'el-icon-s-help' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
